package com.yesallchina.wxapp.officialaccount.api.beans;


import com.yesallchina.wxapp.officialaccount.api.enums.MessageEventTypeEnum;
import com.yesallchina.wxapp.officialaccount.utils.JacksonUtils;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.HashMap;
import java.util.Map;

@XmlRootElement(name = "xml")
public class VoiceMessage extends Message {

    private String MediaId;
    private String Format;
    private String Recognition;

    private Voice Voice;

    public VoiceMessage() {
        super();
        super.setMsgType(MessageEventTypeEnum.VOICE.getMsgType());
    }

    public VoiceMessage(String mediaId) {
        super();
        super.setMsgType(MessageEventTypeEnum.VOICE.getMsgType());
        this.Voice = new Voice();
        this.Voice.setMediaId(mediaId);
    }

    @XmlElement(name = "MediaId")
    public String getMediaId() {
        return MediaId;
    }

    public void setMediaId(String mediaId) {
        MediaId = mediaId;
    }

    @XmlElement(name = "Format")
    public String getFormat() {
        return Format;
    }

    public void setFormat(String format) {
        Format = format;
    }

    @XmlElement(name = "Recognition")
    public String getRecognition() {
        return Recognition;
    }

    public void setRecognition(String recognition) {
        Recognition = recognition;
    }

    @XmlElement(name = "Voice")
    public Voice getVoice() {
        return Voice;
    }

    public void setVoice(Voice voice) {
        this.Voice = voice;
    }

    public static class Voice {
        private String MediaId;

        @XmlElement(name = "MediaId")
        public String getMediaId() {
            return MediaId;
        }

        public void setMediaId(String mediaId) {
            MediaId = mediaId;
        }
    }

    @Override
    public String toCustomerMessage() {
        Map<String, Object> msg = new HashMap<>();
        msg.put("touser", getToUserName());
        msg.put("msgtype", MessageEventTypeEnum.VOICE.getMsgType());
        Map<String, Object> voice = new HashMap<>();
        voice.put("media_id", getMediaId());
        msg.put("voice", voice);
        return JacksonUtils.generate(msg);
    }
}
